clc;clear;clearvars;
load('iris_X.mat', 'iris');
x = iris;
load('iris_Y.mat', 'iris');
y = iris;
% num表示有多少个类标签
num = 3;
n = size(x, 1);
m = size(x, 2);
z = zeros(num, m);
z_lable = [1; 2; 3];
for i = 1 : num
    z(i, :) = sum(x(y == i, :), 1) ./ sum(y == i);
end
U = zeros(n, num);
for i = 1 : n
    Dist = sum((x(i, :) - z).^2, 2);
    D = Dist.^(-1 / (2 - 1));
    Sum_DIST = sum(D);
    for j = 1 : num
        Sum_MULT = D(j, 1);
        U(i, j) = Sum_MULT / Sum_DIST;
    end 
end
% 求U每行最大值以及对应的索引
[~, test_y] = max(U, [], 2);
err_num = sum(test_y ~= y);
fprintf("fnp: iris total: %d err_num: %d\n",n,err_num);